Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | const cheerio = require('cheerio') |
||
17 | describe('test Rules set', () => { |
||
18 | it('rule a should fail', () => { |
||
19 | const result = ruleA(sampleData) |
||
20 | expect(result).toBe('There are 1 <a> tag without rel attribute') |
||
21 | }) |
||
22 | |||
23 | it('rule h1 should fail', () => { |
||
24 | const result = ruleH1(sampleData) |
||
25 | expect(result).toBe('This HTML has more than 1 <h1> tag') |
||
26 | }) |
||
27 | |||
28 | it('rule img should fail', () => { |
||
29 | const result = ruleImg(sampleData) |
||
30 | expect(result).toBe('There are 2 <img> tag without alt attribute') |
||
31 | }) |
||
32 | |||
33 | it('rule strong should fail', () => { |
||
34 | const options = { rules: { strong: { threadhold: 2 } } } |
||
35 | const result = ruleStrong(sampleData, options) |
||
36 | expect(result).toBe('This HTML has more than 2 <strong> tag') |
||
37 | }) |
||
38 | |||
39 | it('rule head should fail', () => { |
||
40 | const failHead = cheerio.load('<html><head></head></html>', {}) |
||
41 | const result = ruleHead(failHead) |
||
42 | expect(result).toBe( |
||
43 | `header that doesn’t have <title> tag\r\nheader that doesn’t have descriptions <meta> tag\r\nheader that doesn’t have keywords <meta> tag` |
||
44 | ) |
||
45 | }) |
||
46 | |||
47 | it('rule a should success', () => { |
||
48 | const successData = cheerio.load('<body><a rel="x"></a></body>', {}) |
||
49 | const result = ruleA(successData) |
||
50 | expect(result).toBeNull() |
||
51 | }) |
||
52 | |||
53 | it('rule h1 should fail', () => { |
||
54 | const successData = cheerio.load('<body><h1></h1></body>', {}) |
||
55 | const result = ruleH1(successData) |
||
56 | expect(result).toBeNull() |
||
57 | }) |
||
58 | |||
59 | it('rule img should fail', () => { |
||
60 | const successData = cheerio.load('<body><img alt="x"></img></body>', {}) |
||
61 | const result = ruleImg(successData) |
||
62 | expect(result).toBeNull() |
||
63 | }) |
||
64 | |||
65 | it('rule strong should fail', () => { |
||
66 | const successData = cheerio.load('<html><strong>strong</strong></html>', { |
||
67 | normalizeWhitespace: true |
||
68 | }) |
||
69 | const options = { rules: { strong: { threadhold: 2 } } } |
||
70 | const result = ruleStrong(successData, options) |
||
71 | expect(result).toBeNull() |
||
72 | }) |
||
73 | |||
74 | it('rule head should fail', () => { |
||
75 | const result = ruleHead(sampleData) |
||
76 | expect(result).toBeNull() |
||
77 | }) |
||
78 | }) |
||
79 |